<template>
  <el-container direction="vertical" class="home-article-wrapper">
    <div class="home-article-header-banner">
      <img :src="articleData.images" class="z-auto" alt="关于">
      <el-breadcrumb class="girl-detail-menu" separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/gankio' }">干货集中营</el-breadcrumb-item>
        <el-breadcrumb-item>文章详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="girl-detail-info">
        <div style="margin-top: 8px"><span class="girl-type"># {{articleData.type}} #</span></div>
        <div class="girl-title">{{articleData.title}}</div>
        <div class="girl-introduce">
          <span>{{articleData.author}}</span>
          <span>发布于 {{articleData.createdAt}}</span>
          <span>{{articleData.views}}</span>
          <span>{{articleData.likeCounts}}</span>
          <span>{{articleData.stars}}</span>
        </div>
      </div>
    </div>
    <div class="article-detail-content">
      <p class="article-detail-introduce" v-html="detailIntroduce">​​​​</p>
      <!-- <img class="detail-image" :src="girlDetailData.url"/>-->
      <div class="detail-annotation">注: 图片与文字均来自网络且无相关性</div>
    </div>
  </el-container>
</template>

<script>
  import { getArticleDetails } from '../../../api/index'
  //引入marked
  const marked = require('marked')
  export default {
    name: 'HomeArticleDetail',
    data () {
      return {
        articleData: {},
        articleId: this.$route.query.id,
        detailIntroduce: ''
      }
    },
    mounted () {
      this.loadArticleDetailData()
    },
    methods: {
      loadArticleDetailData () {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        getArticleDetails(this.articleId).then(data => {
          if (data.status === 100) {
            this.articleData = data.data
            this.detailIntroduce = marked(data.data.markdown)
          }
          loading.close()
        }).catch(error => {
          loading.close()
        })
      }
    }
  }
</script>

<style lang="scss" ref="stylesheet/scss" scoped>
  .home-article-wrapper {
    width: 100%;
    .home-article-header-banner {
      width: 100%;
      margin-bottom: 20px;
      background: rgba(26, 16, 55, 0.5);
      height: 500px;

      img {
        opacity: 0.5;
        object-fit: cover;
        width: 100%;
        height: 100%;
      }
      .girl-detail-menu {
        position: absolute;
        left: 130px;
        top: 160px;
      }

      .girl-detail-info {
        text-align: left;
        position: absolute;
        left: 140px;
        top: 200px;

        .girl-type {
          margin-top: 10px;
          background-color: rgba(44, 99, 255, 1);
          color: white;
          text-align: center;
          padding: 4px 8px;
          font-size: 12px;
          border-radius: 2px;
        }
        .girl-title {
          margin-top: 8px;
          font-size: 20px;
          color: white;
          font-weight: bold;
        }
        .girl-introduce {
          margin-top: 8px;
          color: white;
          font-size: 10px;

          span {
            margin-right: 8px;
          }
        }
      }
    }

    .article-detail-content {
      box-sizing: border-box;
      background-color: rgba(29, 31, 32, 1);
      width: 65%;
      border-radius: 5px;
      padding: 20px;
      margin: 0 auto;

      .article-detail-introduce {
        color: white;
        text-align: left;
        //保留换行空格问题
        white-space: pre-wrap;
        font-weight: bold;
        line-height: 40px;
        //富文本换行
        table-layout: fixed;
        word-break: break-all;
        word-wrap: break-word;
        max-width: 100%;
      }
      /*.detail-image {
        width: 100%;
        margin-top: 5px;
        border-radius: 5px;
        display: block;
        object-fit: fill;
      }*/
      .detail-annotation {
        font-size: 8px;
        margin: 20px 0;
        color: #F2F2F2;
        text-align: left;
      }
    }
  }
</style>
